package com.cwx.mychat.openai.factory;

import com.cwx.mychat.entity.dto.ModelConfigDto;
import com.cwx.mychat.entity.enums.AIModelTypeEnum;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.deepseek.DeepSeekChatOptions;
import org.springframework.ai.deepseek.api.DeepSeekApi;
import org.springframework.stereotype.Component;

/**
 * 作者： cwx
 * 时间： 2025/5/27 14:24
 * 版本： 1.0
 * 注释：
 */
public class DeepSeekAIModelFactory implements ModelFactory<DeepSeekChatModel>{
    @Override
    public boolean support(String modelType) {
        return AIModelTypeEnum.DEEP_SEEK.getType().equalsIgnoreCase(modelType);
    }

    @Override
    public DeepSeekChatModel create(ModelConfigDto modelConfigDto) {

        return DeepSeekChatModel.builder()
                .deepSeekApi(
                        modelConfigDto.getBaseUrl() != null? DeepSeekApi.builder()
                                .apiKey(modelConfigDto.getApiKey())
                                .baseUrl(modelConfigDto.getBaseUrl())
                                .build()
                                : DeepSeekApi.builder()
                                .apiKey(modelConfigDto.getApiKey())
                                .build()
                )
                .defaultOptions(DeepSeekChatOptions.builder()
                        .model(modelConfigDto.getAiModel())
                        .temperature(modelConfigDto.getTemperature())
                        .maxTokens(modelConfigDto.getMaxTokens())
                        .topP(modelConfigDto.getTopP())
                        .build())
                .build();
    }
}
